package com.inspsys.algorithms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspsys.common.annotation.Log;
import com.inspsys.common.core.controller.BaseController;
import com.inspsys.common.core.domain.AjaxResult;
import com.inspsys.common.enums.BusinessType;
import com.inspsys.algorithms.domain.AlgorithmsReport;
import com.inspsys.algorithms.service.IAlgorithmsReportService;
import com.inspsys.common.utils.poi.ExcelUtil;
import com.inspsys.common.core.page.TableDataInfo;

/**
 * 巡检报告Controller
 * 
 * @author inspsys
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/algorithms/report")
public class AlgorithmsReportController extends BaseController
{
    @Autowired
    private IAlgorithmsReportService algorithmsReportService;

    /**
     * 查询巡检报告列表
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlgorithmsReport algorithmsReport)
    {
        startPage();
        List<AlgorithmsReport> list = algorithmsReportService.selectAlgorithmsReportList(algorithmsReport);
        return getDataTable(list);
    }

    /**
     * 导出巡检报告列表
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:export')")
    @Log(title = "巡检报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmsReport algorithmsReport)
    {
        List<AlgorithmsReport> list = algorithmsReportService.selectAlgorithmsReportList(algorithmsReport);
        ExcelUtil<AlgorithmsReport> util = new ExcelUtil<AlgorithmsReport>(AlgorithmsReport.class);
        util.exportExcel(response, list, "巡检报告数据");
    }

    /**
     * 获取巡检报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(algorithmsReportService.selectAlgorithmsReportById(id));
    }

    /**
     * 新增巡检报告
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:add')")
    @Log(title = "巡检报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgorithmsReport algorithmsReport)
    {
        return toAjax(algorithmsReportService.insertAlgorithmsReport(algorithmsReport));
    }

    /**
     * 修改巡检报告
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:edit')")
    @Log(title = "巡检报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgorithmsReport algorithmsReport)
    {
        return toAjax(algorithmsReportService.updateAlgorithmsReport(algorithmsReport));
    }

    /**
     * 删除巡检报告
     */
    @PreAuthorize("@ss.hasPermi('algorithms:report:remove')")
    @Log(title = "巡检报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(algorithmsReportService.deleteAlgorithmsReportByIds(ids));
    }
}
